/**
 * 设计一个不浪费空间的循环队列
 */
class MyCircularQueue {

    private int[] arr;
    private int usedSize;
    private int front;
    private int rear;

    public MyCircularQueue(int k) {
        arr = new int[k];
    }
    
    public boolean enQueue(int value) {
        if(isFull()) {
            return false;
        }
        arr[rear] = value;
        rear = (rear + 1) % arr.length;
        usedSize++;
        return true;
    }
    
    public boolean deQueue() {
        if(isEmpty()) {
            return false;
        }
        front = (front + 1) % arr.length;
        usedSize--;
        return true;
    }
    
    public int Front() {
        if(isEmpty()) {
            return -1;
        }
        return arr[front];
    }
    
    public int Rear() {
        if(isEmpty()) {
            return -1;
        }
        int temp = (rear - 1 + arr.length) % arr.length;
        return arr[temp];
    }
    
    public boolean isEmpty() {
        if(usedSize == 0) {
            return true;
        }
        return false;
    }
    
    public boolean isFull() {
        if(usedSize == arr.length) {
            return true;
        }
        return false;
    }
}